﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Frm_Demande_Clients
    Public num As Integer = -1
    Dim c As Integer = 0
    Public Function Ndemande() As Integer
        Try
            Cmd = New SqlCommand("select max(N_demande) from clients_Demande", Con)
            open()
            If Cmd.ExecuteScalar() IsNot DBNull.Value Then
                c = Cmd.ExecuteScalar()
            End If
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        Return c + 1
    End Function
    Public Sub vider()
        If Comb_salle.Items.Count > 0 Then
            Comb_salle.SelectedIndex = 0
        End If

        If Combo_type_reserv.Items.Count > 0 Then
            Combo_type_reserv.SelectedIndex = 0
        End If

        If Comb_motif_reserv.Items.Count > 0 Then
            Comb_motif_reserv.SelectedIndex = 0
        End If
        txt_prix_salle.Text = 0
        txt_n_demande.Clear()
        txt_remarq.Clear()
        List_Repas.Items.Clear()
        List_tous.Items.Clear()
        txt_NomA.Clear()
        txt_NomB.Clear()
        txtPrixAdjoint.Clear()
        If cmbAdjoint.Items.Count > 0 Then
            cmbAdjoint.SelectedIndex = 0
        End If
        lstViewAdjoint.Items.Clear()
    End Sub

    Public Sub Comb_Motif_Reservation()
        Try
            Comb_motif_reserv.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Motif_Reservation", Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows Then
                Do While Dr.Read()
                    Comb_motif_reserv.Items.Add(Dr("Motif_Reservation"))
                Loop
            End If
            Dr.Close()
            cnClose()
            If Comb_motif_reserv.Items.Count > 0 Then
                Comb_motif_reserv.SelectedIndex = 0
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Public Sub Comb_autre_Equipement()
        Try
            Comb_Nom_Equipement.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Equipement_Clients", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                Comb_Nom_Equipement.Items.Add(Dr("autre_Equipe"))
            Loop
            Dr.Close()
            cnClose()
            If Comb_Nom_Equipement.Items.Count > 0 Then
                Comb_Nom_Equipement.SelectedIndex = 0
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Public Sub Comb_Plats()
        Try
            Comb_Repas.Items.Clear()
            Cmd = New SqlCommand("Select * From Comb_Plat", Con)
            open()
            Dr = Cmd.ExecuteReader()
            If Dr.HasRows Then
                Do While Dr.Read()
                    Comb_Repas.Items.Add(Dr("Plat"))
                Loop
            End If
            Dr.Close()
            cnClose()
            If Comb_Repas.Items.Count > 0 Then
                Comb_Repas.SelectedIndex = 0
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
    End Sub

    Private Sub btn_parcour_motif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_parcour_motif.Click
        Frm_Motif.Show()
    End Sub

    Private Sub btn_parc_apperitif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_parc_apperitif.Click
        Frm_entrer.Show()
    End Sub

    Private Sub Frm_Demande_Clients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Comb_salle.SelectedIndex = 0
        Combo_type_reserv.SelectedIndex = 0

        Comb_autre_Equipement()
        Comb_Motif_Reservation()
        Comb_Plats()

        'tarik
        open()
        remplirLstAdjoint("select * from adjoints")
        remplirCmbAdjoint(cmbAdjoint)
        'remplir les adjoints de l'événement
        Try
            comb_client.Items.Clear()
            Cmd = New SqlCommand("Select * From Clients where Location='Non'", Con)
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                If Dr("Type_Client") = "Entreprise" Then
                    comb_client.Items.Add(Dr("Nom_entreprise"))
                Else
                    comb_client.Items.Add(Dr("Nom") & "  " & Dr("Prenom"))
                End If
            Loop
            Dr.Close()
            cnClose()
            If comb_client.Items.Count > 0 Then
                comb_client.SelectedIndex = comb_client.Items.Count - 1
            End If

        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        '----------------------------------------
        txt_n_demande.Text = Ndemande()

    End Sub

    Private Sub btn_supp_apres_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp_apres.Click
        For Each i As ListViewItem In List_Repas.SelectedItems
            List_Repas.Items.Remove(i)
        Next
    End Sub


    Private Sub btn_nouv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_nouv.Click
        vider()
        '----------------------------------------
        txt_n_demande.Text = Ndemande()
    End Sub

    Private Sub btn_ajou_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajou.Click
        cnClose()
        Dim idDem As Integer
            Try
                Cmd = New SqlCommand("Select * From Clients Where Location='Non'", Con)
                open()
                Dr = Cmd.ExecuteReader()
                Do While Dr.Read()

                    If Dr("Nom_entreprise") = comb_client.SelectedItem.ToString Then
                        num = Dr("Id_Client")
                    ElseIf (Dr("Nom") & "  " & Dr("Prenom")) = comb_client.SelectedItem.ToString Then
                        num = Dr("Id_Client")
                    End If
                Loop
                Dr.Close()
                cnClose()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                cnClose()
            End Try

            If txt_n_demande.Text <> "" Then
                If (Combo_type_reserv.SelectedItem <> "Salle Vide") Or (Combo_type_reserv.SelectedItem = "Salle Vide" And txt_prix_salle.Text <> 0) Then
                    If MsgBox("Vous Voulez Vraiment Ajouter La Demande ?", MsgBoxStyle.YesNo Or MsgBoxStyle.Information, "Ajouter La Demande") = MsgBoxResult.Yes Then
                        Try
                            'Tarik(Pour l'héritage voir location diagrame)
                            Cmd = New SqlCommand("INSERT INTO [Salle_Mariage].[dbo].[locEvent]" &
                                                " select MAX(id) + 1 from locEvent ", Con)
                            open()
                            Cmd.ExecuteNonQuery()

                            Cmd.CommandText = "select MAX(id) from locEvent"
                        idDem = Cmd.ExecuteScalar
                            'end

                            Cmd = New SqlCommand("insert into Clients_Demande " & _
                            "values (" & idDem & ",@Date_evenement,@lieu,@adresse,@Id_Client,@jour_nuit,@N_demande,@Motif_Reservation,@Type_Reservation,@Prix_salle,@Remarque,@Date_reservation,@Marie,@Mariee,'false')", Con)

                            Cmd.Parameters.Add("@Date_evenement", SqlDbType.Date).Value = CDate(Date_evenment.Value.Date)
                            Cmd.Parameters.Add("@lieu", SqlDbType.VarChar).Value = Comb_salle.SelectedItem
                            If Comb_salle.SelectedItem = "Salle 1" Or Comb_salle.SelectedItem = "Salle 2" Then
                                Cmd.Parameters.Add("@adresse", SqlDbType.VarChar).Value = "laylat al omr"
                            Else
                                Cmd.Parameters.Add("@adresse", SqlDbType.VarChar).Value = txt_adresse.Text
                            End If
                            Cmd.Parameters.Add("@Id_Client", SqlDbType.Int).Value = num
                            If Radio_nuit.Checked = True Then
                                Cmd.Parameters.Add("@jour_nuit", SqlDbType.VarChar).Value = "Nuit"
                            ElseIf Radio_jour.Checked = True Then
                                Cmd.Parameters.Add("@jour_nuit", SqlDbType.VarChar).Value = "Jour"
                            End If
                            Cmd.Parameters.Add("@N_demande", SqlDbType.VarChar).Value = txt_n_demande.Text
                            Cmd.Parameters.Add("@Type_Reservation", SqlDbType.VarChar).Value = Combo_type_reserv.SelectedItem
                            Cmd.Parameters.Add("@Motif_Reservation", SqlDbType.VarChar).Value = Comb_motif_reserv.SelectedItem
                            Cmd.Parameters.Add("@Remarque", SqlDbType.Text).Value = txt_remarq.Text
                            Cmd.Parameters.Add("@Date_reservation", SqlDbType.Date).Value = CDate(Date_res.Value.Date)
                            Cmd.Parameters.Add("@Prix_salle", SqlDbType.Float).Value = CDbl(txt_prix_salle.Text)
                            Cmd.Parameters.Add("@Marie", SqlDbType.VarChar).Value = txt_NomA.Text
                            Cmd.Parameters.Add("@Mariee", SqlDbType.VarChar).Value = txt_NomB.Text

                            open()
                            Cmd.ExecuteNonQuery()
                            'Tarik
                            'code pour ajouter l'adjoint
                            If lstViewAdjoint.Items.Count > 0 Then
                                Cmd.CommandText = "INSERT INTO [adjointEvenement]([idAdjoint],[id_dem],[prix]) " &
                                                    "VALUES(@idAdjoint,@id_dem,@prix)"
                                Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = idDem
                                Cmd.Parameters.Add("@idAdjoint", SqlDbType.Int)
                                Cmd.Parameters.Add("@prix", SqlDbType.Float)
                                For Each it As ListViewItem In lstViewAdjoint.Items
                                    Cmd.Parameters("@idAdjoint").Value = CInt(it.SubItems(0).Text)
                                    Cmd.Parameters("@prix").Value = CDbl(it.SubItems(3).Text)
                                    Cmd.ExecuteNonQuery()
                                Next
                            End If
                            'end code
                            'end
                            cnClose()
                        Catch ex As SqlException

                            If ex.Message.Contains("uniq_Clients_Demande") Then
                                MsgBox("La date est Reservée", MsgBoxStyle.Exclamation)
                                cnClose()
                                Exit Sub
                            ElseIf ex.Message.Contains("IX_Clients_Demande") Then
                                MsgBox("Changer le num demande svp", MsgBoxStyle.Exclamation)
                                cnClose()
                                Exit Sub
                            Else
                                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                                cnClose()
                                Exit Sub
                            End If

                        End Try
                        '________________________________________________________________________'




                        Try
                            For i As Integer = 0 To List_tous.Items.Count - 1
                                Cmd = New SqlCommand("insert into Clients_Equip values (@id_dem,@Equipement,@Nbr,@Prix_Unitaire,@Prix_Total,@Remarq)", Con)
                            Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = idDem
                                Cmd.Parameters.Add("@Equipement", SqlDbType.VarChar).Value = List_tous.Items(i).SubItems(0).Text
                                Cmd.Parameters.Add("@Prix_Unitaire", SqlDbType.Float).Value = List_tous.Items(i).SubItems(1).Text
                                Cmd.Parameters.Add("@Nbr", SqlDbType.Float).Value = List_tous.Items(i).SubItems(2).Text
                                Cmd.Parameters.Add("@Prix_Total", SqlDbType.Float).Value = List_tous.Items(i).SubItems(3).Text
                                Cmd.Parameters.Add("@Remarq", SqlDbType.Text).Value = List_tous.Items(i).SubItems(4).Text

                                open()
                                Cmd.ExecuteNonQuery()
                                cnClose()

                            Next
                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try
                        '________________________________________________________________________'
                        Try
                            For i As Integer = 0 To List_Repas.Items.Count - 1
                                Cmd = New SqlCommand("insert into Clients_Repas values (@id_dem,@Repas)", Con)
                            Cmd.Parameters.Add("@id_dem", SqlDbType.Int).Value = idDem
                                Cmd.Parameters.Add("@Repas", SqlDbType.VarChar).Value = List_Repas.Items(i).SubItems(0).Text


                                open()
                                Cmd.ExecuteNonQuery()
                                cnClose()
                            Next
                            num = -1
                            vider()
                            MsgBox("Demande Ajouté", MsgBoxStyle.Information, "Réussi !")

                        Catch ex As Exception
                            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
                            cnClose()
                        End Try

                    End If
                Else
                    MsgBox("Entrez les Données", MsgBoxStyle.Critical, "Erreur !")
                End If
            Else
                MsgBox("Entrez les Données", MsgBoxStyle.Critical, "Erreur !")
            End If
            '----------------------------------------
            txt_n_demande.Text = Ndemande()
    End Sub

    Private Sub btn_Rechrcher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Rechrcher.Click
        Frm_liste_Demande.MdiParent = Frm_Main
        Frm_liste_Demande.Show()
        liste = "demande"
        Me.Close()
    End Sub

    Private Sub Comb_salle_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Comb_salle.KeyPress
        e.Handled = True
    End Sub


    Private Sub Comb_salle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_salle.SelectedIndexChanged
        If Comb_salle.SelectedItem = "Salle 1" Then
            txt_adresse.Clear()
            txt_adresse.Enabled = False
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Salle Vide")
            Combo_type_reserv.Items.Add("Salle Avec Matériels")
            Combo_type_reserv.Items.Add("Salle Avec Repas")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = True
        ElseIf Comb_salle.SelectedItem = "Salle 2" Then
            txt_adresse.Clear()
            txt_adresse.Enabled = False
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Salle Vide")
            Combo_type_reserv.Items.Add("Salle Avec Matériels")
            Combo_type_reserv.Items.Add("Salle Avec Repas")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = True
        ElseIf Comb_salle.SelectedItem = "Autre Salle" Then
            txt_adresse.Enabled = True
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Matériels et Repas")
            Combo_type_reserv.Items.Add("Salle Avec Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = False
            txt_prix_salle.Text = 0
        ElseIf Comb_salle.SelectedItem = "Domicile" Then
            txt_adresse.Enabled = True
            txt_adresse.Enabled = True
            Combo_type_reserv.Items.Clear()
            Combo_type_reserv.Items.Add("Matériels et Repas")
            Combo_type_reserv.SelectedIndex = 0
            txt_prix_salle.Enabled = False
            txt_prix_salle.Text = 0
        End If
        '---------------------------------------------------------------------
        'If Con.State = ConnectionState.Open Then
        '    cnClose
        'End If
        'Try
        '    Cmd = New SqlCommand("Select Date_Reservation,lieu From Clients_Demande", Con)
        '    open()
        '    Dr = Cmd.ExecuteReader()
        '    Do While Dr.Read()

        '        If Dr("Date_Reservation") = CDate(Date_evenment.Value.Date) And Dr("lieu") = Comb_salle.SelectedItem.ToString Then
        '            MsgBox("La date est reservée pour cette Salle", MsgBoxStyle.Critical, "Erreur !")
        '            Date_evenment.Value = CDate("2010/01/01")

        '            MsgBox("La date a ete changé avec succes", MsgBoxStyle.Information, "Succes !")
        '            Dr.Close()
        '            cnClose
        '            Exit Do
        '        End If

        '    Loop
        '    Dr.Close()
        '    cnClose
        'Catch ex As Exception
        '    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        '    cnClose
        'End Try
    End Sub

    Private Sub Date_evenment_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Date_evenment.ValueChanged
        'If Con.State = ConnectionState.Open Then
        '    cnClose
        'End If
        'Try
        '    Cmd = New SqlCommand("Select Date_Reservation,lieu From Clients_Demande", Con)
        '    open()
        '    Dr = Cmd.ExecuteReader()
        '    Do While Dr.Read()

        '        If Dr("Date_Reservation") = CDate(Date_evenment.Value.Date) And Dr("lieu") = Comb_salle.SelectedItem.ToString Then
        '            MsgBox("La date est reservée pour cette Salle", MsgBoxStyle.Critical, "Erreur !")
        '            Date_evenment.Value = CDate("2010/01/01")
        '            MsgBox("La date a ete changé avec succes", MsgBoxStyle.Information, "Succes !")
        '            Dr.Close()
        '            cnClose
        '            Exit Do
        '        End If

        '    Loop
        '    Dr.Close()
        '    cnClose
        'Catch ex As Exception
        '    MsgBox(ex.Message, MsgBoxStyle.Exclamation)
        '    cnClose
        'End Try
    End Sub
    Private Sub btn_ajou_apperitif_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajou_apperitif.Click
        repasExist = False
        For Each it As ListViewItem In List_Repas.Items
            If it.SubItems(0).Text = Comb_Repas.SelectedItem Then
                repasExist = True
                Exit For
            End If
        Next
        If Not repasExist Then
            Dim Line As ListViewItem = New ListViewItem(New String() {Comb_Repas.SelectedItem})
            List_Repas.Items.Add(Line)
        End If
    End Sub

    Private Sub btn_rech_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_rech.Click
        Me.Enabled = False
        Frm_Recherche_clients.Show()
        rech = "demande"
    End Sub


    Private Sub btn_parc_equi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_parc_equi.Click
        Frm_Autre_Equip.Show()
    End Sub

    Private Sub btn_ajou_equip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ajou_equip.Click
        If txt_nbr.Text <> "" And txt_prix_unit.Text <> "" Then
            Dim Line As ListViewItem = New ListViewItem(New String() {Comb_Nom_Equipement.SelectedItem, txt_prix_unit.Text, txt_nbr.Text, txt_prix_total.Text, txt_remarq_matr.Text})
            List_tous.Items.Add(Line)
            txt_prix_unit.Text = 0
            txt_nbr.Clear()
            txt_prix_total.Clear()
            txt_remarq_matr.Clear()
        End If

    End Sub

    Private Sub btn_supp_equip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_supp_equip.Click
        For Each i As ListViewItem In List_tous.SelectedItems
            List_tous.Items.Remove(i)
        Next
        txt_prix_unit.Clear()
        txt_nbr.Clear()
        txt_prix_total.Clear()
        txt_remarq_matr.Clear()
    End Sub

    Private Sub txt_prix_unit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_prix_unit.TextChanged
        Dim selStart As Integer = txt_prix_unit.SelectionStart
        Dim selMoveLeft As Integer = 0
        Dim newStr As String = "" 'Build a new string by copying each valid character from the existing string. The new string starts as blank and valid characters are added 1 at a time.

        For i As Integer = 0 To txt_prix_unit.Text.Length - 1

            If "0123456789,".IndexOf(txt_prix_unit.Text(i)) <> -1 Then 'Characters that are in the allowed set will be added to the new string.
                newStr = newStr & txt_prix_unit.Text(i)

            ElseIf i < selStart Then 'Characters that are not valid are removed - if these characters are before the cursor, we need to move the cursor left to account for their removal.
                selMoveLeft = selMoveLeft + 1

            End If
        Next

        txt_prix_unit.Text = newStr 'Place the new text into the textbox.
        txt_prix_unit.SelectionStart = selStart - selMoveLeft 'Move the cursor to the appropriate location.


        If txt_prix_unit.Text = "" Then
            txt_prix_total.Text = 0
        End If

        Try
            If txt_prix_unit.Text <> "" And txt_nbr.Text <> "" Then
                txt_prix_total.Text = CDbl(txt_prix_unit.Text) * CDbl(txt_nbr.Text)
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try

    End Sub

    Private Sub txt_nbr_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_nbr.TextChanged
        Dim selStart As Integer = txt_nbr.SelectionStart
        Dim selMoveLeft As Integer = 0
        Dim newStr As String = "" 'Build a new string by copying each valid character from the existing string. The new string starts as blank and valid characters are added 1 at a time.

        For i As Integer = 0 To txt_nbr.Text.Length - 1

            If "0123456789,".IndexOf(txt_nbr.Text(i)) <> -1 Then 'Characters that are in the allowed set will be added to the new string.
                newStr = newStr & txt_nbr.Text(i)

            ElseIf i < selStart Then 'Characters that are not valid are removed - if these characters are before the cursor, we need to move the cursor left to account for their removal.
                selMoveLeft = selMoveLeft + 1

            End If
        Next

        txt_nbr.Text = newStr 'Place the new text into the textbox.
        txt_nbr.SelectionStart = selStart - selMoveLeft 'Move the cursor to the appropriate location.


        If txt_nbr.Text = "" Then
            txt_prix_total.Text = 0
        End If

        Try
            If txt_prix_unit.Text <> "" And txt_nbr.Text <> "" Then
                txt_prix_total.Text = CDbl(txt_prix_unit.Text) * CDbl(txt_nbr.Text)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try

    End Sub

    Private Sub txt_prix_salle_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txt_prix_salle.KeyPress
        Dim allowedChars As String = "1234567890,"
        If txt_prix_salle.Text.Contains(",") Then
            allowedChars = "1234567890"
        End If
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
    End Sub

    Private Sub txt_prix_salle_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_prix_salle.TextChanged
        If txt_prix_salle.Text = "" Then
            txt_prix_salle.Text = 0
        End If
    End Sub

    Private Sub Combo_type_reserv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_type_reserv.SelectedIndexChanged
        If Combo_type_reserv.SelectedItem = "Salle Vide" Then
            Group_Matériels.Enabled = False
            Group_Repas.Enabled = False
        ElseIf Combo_type_reserv.SelectedItem = "Salle Avec Matériels" Then
            Group_Matériels.Enabled = True
            Group_Repas.Enabled = False
        ElseIf Combo_type_reserv.SelectedItem = "Salle Avec Matériels et Repas" Or Combo_type_reserv.SelectedItem = "Matériels et Repas" Or Combo_type_reserv.SelectedItem = "Salle Avec Repas" Then
            If Combo_type_reserv.SelectedItem = "Salle Avec Matériels et Repas" Or Combo_type_reserv.SelectedItem = "Salle Avec Repas" Then
                txt_prix_salle.Enabled = True
            End If
            If Combo_type_reserv.SelectedItem = "Matériels et Repas" Then
                txt_prix_salle.Enabled = False
            End If
            Group_Matériels.Enabled = True
            Group_Repas.Enabled = True
            ElseIf Combo_type_reserv.SelectedItem = "Repas" Then
                Group_Matériels.Enabled = False
                Group_Repas.Enabled = True

            End If
    End Sub


    Private Sub List_tous_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles List_tous.SelectedIndexChanged
        With List_tous
            If .SelectedIndices.Count > 0 Then
                For i As Integer = 0 To .SelectedIndices.Count - 1
                    Comb_Nom_Equipement.Text = (.Items(.SelectedIndices(i)).SubItems(0).Text)
                    txt_prix_unit.Text = (.Items(.SelectedIndices(i)).SubItems(1).Text)
                    txt_nbr.Text = (.Items(.SelectedIndices(i)).SubItems(2).Text)
                    txt_remarq_matr.Text = (.Items(.SelectedIndices(i)).SubItems(4).Text)

                Next
            End If
        End With
    End Sub

    Private Sub Comb_Nom_Equipement_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_Nom_Equipement.SelectedIndexChanged
        If Comb_Nom_Equipement.Text = "Femmes de Ménage" And Comb_salle.Text = "Salle1" Then
            txt_nbr.Text = 3
        End If
        If Comb_Nom_Equipement.Text = "Femmes de Ménage" And Comb_salle.Text = "Salle2" Then
            txt_nbr.Text = 2
        End If
        If Comb_Nom_Equipement.Text = "Télévisions" And Comb_salle.Text = "Salle1" Then
            txt_nbr.Text = 4
        End If
        If Comb_Nom_Equipement.Text = "Télévisions" And Comb_salle.Text = "Salle2" Then
            txt_nbr.Text = 2
        End If
        If Comb_Nom_Equipement.Text = "Canapé salle" Then
            txt_nbr.Text = 10
        End If
        If Comb_Nom_Equipement.Text = "Piéce Monté" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Orchestre" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Berka du thé" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Neggafa" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "3amariya" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Ahwach" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Caméra" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Canapé mariée" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Cheval" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "DJ" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Jeux du Lumiére" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Limousine" Then
            txt_nbr.Text = 1
        End If
        If Comb_Nom_Equipement.Text = "Réception" Then
            txt_nbr.Text = 1
        End If
    End Sub

    Private Sub Comb_motif_reserv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Comb_motif_reserv.SelectedIndexChanged
        If Comb_motif_reserv.Items.Count > 0 Then
            If Comb_motif_reserv.SelectedItem.ToString = "Mariage" Then
                lblMarie.Text = "Le marié :"
                lblMariee.Text = "La mariée :"
                lblMariee.Visible = True
                txt_NomB.Visible = True
            Else
                lblMarie.Text = "Pour :"
                lblMariee.Visible = False
                txt_NomB.Visible = False
            End If
        End If
    End Sub

    Private Sub btnRechAdjoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechAdjoint.Click
        Me.Enabled = False
        frm = New Form
        frm = Me
        frmRechAdj.Show()
    End Sub

    Private Sub btnAddAdj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddAdj.Click
            If Not String.IsNullOrWhiteSpace(txtPrixAdjoint.Text) And Not String.IsNullOrEmpty(txtPrixAdjoint.Text) Then

                For Each lstItem As ListViewItem In lstViewAdjoint.Items
                    If CInt(lstItem.SubItems(0).Text) = CType(cmbAdjoint.SelectedItem, DictionaryEntry).Key Then
                        MsgBox("Déjà ajouter")
                        Exit Sub
                    End If
                Next

                For Each adj In lstAdjoints
                    If adj.idAdjoint = CType(cmbAdjoint.SelectedItem, DictionaryEntry).Key Then
                        lstViewAdjoint.Items.Add(New ListViewItem(New String() {adj.idAdjoint, adj.nom & " " & adj.prenom, adj.professino, txtPrixAdjoint.Text}))
                    End If
                Next
                txtPrixAdjoint.Clear()
                cmbAdjoint.SelectedIndex = 0
            Else
                MsgBox("Vous devez entrer le prix!!!", MsgBoxStyle.Critical, "Erreur")
            End If
    End Sub

    Private Sub btnDeleteAdj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteAdj.Click
        If lstViewAdjoint.SelectedItems.Count > 0 Then
            lstViewAdjoint.SelectedItems(0).Remove()
        End If
    End Sub

    Private Sub txtPrixAdjoint_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrixAdjoint.KeyPress
        Dim allowedChars As String = "1234567890,"
        If txtPrixAdjoint.Text.Contains(",") Then
            allowedChars = "1234567890"
        End If
        If e.KeyChar = ChrW(8) Then
            e.Handled = False
        ElseIf allowedChars.IndexOf(e.KeyChar) = -1 Then
            e.Handled = True
        End If
    End Sub
End Class